﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using KHMI.Draw.Properties;

namespace KHMI
{
    public partial class KKPropertie : PropertyGrid
    {
        private DrawTools.KKDraw kkDrawSelect;

        public DrawTools.KKDraw KkDrawSelect
        {
            get { return kkDrawSelect; }
            set
            {
                kkDrawSelect = value;
                kkDrawSelect.MouseDown += new MouseEventHandler(kkDrawSelect_MouseDown);
                this.PropertyValueChanged += new PropertyValueChangedEventHandler
                    (KKPropertie_PropertyValueChanged);
            }
        }

        void KKPropertie_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
        {
            kkDrawSelect.Invalidate(true);
        }

        void kkDrawSelect_MouseDown(object sender, MouseEventArgs e)
        {
            if (KkDrawSelect.GraphicsList.GetProperties() != null)
            {
                if (KkDrawSelect.GraphicsList.GetProperties() is Control 
                    //|| KkDrawSelect.GraphicsList.GetProperties() is UserControl
                    )
                {
                    this.SelectedObject = KkDrawSelect.GraphicsList.GetProperties();
                } 
                else
                {
                    this.setSelDraw(KkDrawSelect.GraphicsList.GetProperties(),
                    KkDrawSelect.GraphicsList.GetProperties().GetType());
                }
                
            }
            else
            {
                //this.setSelDraw(KkDrawSelect, KkDrawSelect.GetType());
                this.SelectedObject = null;
            }
        }

        public KKPropertie()
        {
            InitializeComponent();
        }

        private void setSelDraw(object pSelectObject, Type tp)
        {
            this.SelectedObject = new CustomProperty(pSelectObject, tp);
        }
    }
}
